package com.fs.sys.web;

import com.fs.sys.bean.dto.AppDTO;
import com.fs.common.annotations.Auth;
import com.fs.sys.bean.dto.TenantAppDTO;
import com.fs.sys.bean.req.TenantAppAddReq;
import com.fs.sys.bean.resp.TenantAppResp;
import com.fs.sys.service.TenantAppService;
import com.fs.sys.entityservice.TenantAppEntityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 租户应用控制器 
 * @author Coder Generator 2025-06-13 21:28:11 
 **/
@RestController
@RequestMapping("/sys/tenant-app")
@Slf4j
@Tag(name = "租户应用控制器")
public class TenantAppController {
    @Autowired
    private TenantAppEntityService service;

    @Autowired
    private TenantAppService tenantAppService;

    @PostMapping("add")
    @Operation(summary = "新增")
    @Auth
    public void add(@RequestBody @Validated TenantAppAddReq req) {
        tenantAppService.add(req.getTenantId(), req.getAppIds(), req.getExpireDate());
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary = "删除")
    @Auth
    public void delete(@PathVariable("id") String id) {
        service.delete(id);
    }

    @GetMapping("detail/{id}")
    @Operation(summary = "根据id查找记录")
    public TenantAppDTO findById(@PathVariable("id") String id) {
        return service.findById(id).orElse(null);
    }

    /**
     * 查找租户未拥有的应用列表
     * @param tenantId 租户id
     * @return 租户未拥有的应用列表
     */
    @GetMapping("not-dispatched")
    public List<AppDTO> findNotDispatched(String tenantId) {
        return tenantAppService.findNotDispatched(tenantId);
    }

    @GetMapping("dispatched")
    @Operation(summary = "查询-不分页")
    public List<TenantAppResp> query(String tenantId) {
        return tenantAppService.getTenantDispatchedApps(tenantId);
    }
}